<?php

class Quantri_Model_HangHoaDVNgay extends Zend_Db_Table_Abstract
{
    protected $_name="dmhanghoadvngay";
    protected $_primary="Id";
    
    var $Id, $Ngay, $IdHangHoaDV, $SoLuong, $TrangThai;
    
    public function __construct() {
    	$this->_name = Zend_Registry::get('tablePrefix') . $this->_name;
    	    
    	parent::__construct();
    }
    
	
	public function GetAll() {	    
	   
	    $query = $this->_db->select()
	    	->from(array('T1'=>'os_dmhanghoadvngay'))
	    	->joinLeft(array('T2' => 'os_dmhanghoadv'), 'T1.IdHangHoaDV = T2.Id', array('T2.Ten as TenHanghoadv'));
	   	   
	    $stmt = $this->_db->query($query);
	    
		
	    return $result = $stmt->fetchAll();		
    }
    
    public function save()
    {
        $data = array(
        	'Ngay' 	=> $this->Ngay,
        	'IdHangHoaDV' 	=> $this->IdHangHoaDV,
        	'SoLuong' 	=> $this->SoLuong, 
        	'TrangThai' => $this->TrangThai       	
        );
        
        if($this->Id=="-1")
        	$this->insert($data);
       	else
       	    $this->update($data, "Id = '$this->Id'");
    }
    
    public function saveupdate()
    {
    	$data = array(    			
    			'SoLuong' 	=> $this->SoLuong,
    			'TrangThai' => $this->TrangThai
    	);
    	$this->update($data, "Id = '$this->Id'");
    }
    
    public function xoa($id)
    {
        $this->delete("id='". $id . "'");
    }
    
    public function GetById()
    {      
        return $this->fetchAll("Id='$this->Id'", "", 1)->toArray();
    }
    
    public function UpdateTrangthai()
    {
        $data = array(
        	'TrangThai' => $this->TrangThai
        );
        
        $this->update($data, "Id = '$this->Id'");
    }
    
    public function GetFullHanghoadv()
    {
        //echo $this->Id;
        $query = $this->_db->select()
        					->from(array('T1'=>'os_dmhanghoadvngay'))
        					->joinLeft(array('T2' => 'os_dmhanghoadv'), 'T1.IdHangHoaDV = T2.Id', array('T2.Ten as TenHanghoadv'))
        					->where("T1.Id = $this->Id");
    						
        $stmt = $this->_db->query($query);
        return $result = $stmt->fetchAll();
        
    }
	
}

